<?php get_header(); ?>

<?php $odd_or_even = 'odd'; ?>
<div id="trac-actions">
  <div id="ticket-btn"><a href="<?php bloginfo('url'); ?>/rapportera/">Ny Rapport</a></div>
  <nav id="filter-nav">
        <span>Filtrera rapporter efter:</span> 
    <?php wp_dropdown_categories('name=ticket_component&taxonomy=category&hide_empty=0&show_option_none=- Komponent -'); ?>
    <script type="text/javascript">
        <!--
    var dropdown = document.getElementById("ticket_component");
    function onCatChange() {
                if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
                        location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
                }
    }
    dropdown.onchange = onCatChange;
        -->
        </script>
    <form action="<?php bloginfo('url'); ?>" method="get">
    <?php
    $taxonomies = array('typ');
    $args = array('orderby'=>'name','hide_empty'=>false);
    $select = get_terms_dropdown($taxonomies, $args);
    
    $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    echo $select;
    ?>
        <noscript><input type="submit" value="ok" /></noscript>
    </form>
  </nav>
  <div id="trac-search">
    <form action="<?php bloginfo('url'); ?>/">
      <input name="s" type="text" id="text-search" placeholder="Sök rapport..." />
      <input name="submit" id="submit-search" type="submit" value="" />
    </form>
  </div>
  <div class="clearer"></div>
</div>
<table id="tracTable" class="tablesorter tracker-table">
  <thead>
  <tr>
    <th class="first"><span>#ID</span></th>
    <th>Rapport</th>
    <th><span>Komponent</span></th>
    <th><span>Typ</span></th>
    <th><span>Prioritet</span></th>
    <th><span>Allvarlighetsgrad</span></th>
    <th class="last"><span>Målversion</span></th>
  </tr>
</thead>
<tbody>        
        <?php if (have_posts()) : ?>

		<?php while (have_posts()) : the_post(); ?>

  		<tr class="row <?php echo $odd_or_even; echo is_object_in_term($post->ID,'prioritet','Högsta') ? ' highest-prio' : ' normal-prio'; ?>">
		<?php $odd_or_even = ('odd'==$odd_or_even) ? 'even' : 'odd'; ?>
		
            <td class="ticket-id ticket-<?php echo is_object_in_term($post->ID,'ticket_status', array('Åtgärdad','Åtgärdad i trunk','Inte en bugg','Kommer inte åtgärdas','Redan åtgärdad','Kunde inte återskapas')) ? 'closed' : 'open'; ?>"><a href="<?php the_permalink(); ?>">#<?php the_ID(); ?></a></td>
            <td class="ticket-<?php echo is_object_in_term($post->ID,'ticket_status', array('Åtgärdad','Åtgärdad i trunk','Inte en bugg','Kommer inte åtgärdas','Redan åtgärdad','Kunde inte återskapas')) ? 'closed' : 'open'; ?>"><img class="<?php echo is_object_in_term($post->ID,'prioritet','Högsta') ? 'highest' : 'hidden'; ?>" src="<?php bloginfo('template_url'); ?>/images/highest.png" width="24" height="24" alt="highest-priority" /><!-- Sweet icon from Fugue icon set <http://p.yusukekamiyamane.com/> --><p class="ticket-title"><a href="<?php the_permalink(); ?>" title="Rapport #<?php the_ID(); ?>" rel="bookmark"><?php the_title(); ?></a></p>
            <span class="ticket-meta">Rapporterat av <?php if (get_the_author_meta('ID') == '2') { echo '<span style="color:#000;">'.get_post_meta($post->ID, 'ticket_poster', true).'</span>'; } else { echo get_the_author_link(); } ?> den <?php the_time('j F, Y'); ?></span></td>
            <td><?php the_category(', '); ?></td>
            <td><?php the_terms( $post->ID, 'typ', ' ', ', ', ' ' ); ?></td>
            <td><?php the_terms( $post->ID, 'prioritet', ' ', ', ', ' ' ); ?></td>
            <td><?php the_terms( $post->ID, 'allvarlighetsgrad', ' ', ', ', ' ' ); ?></td>
            <td class="last"><?php the_terms( $post->ID, 'milestone', ' ', ', ', ' ' ); ?></td>
        </tr>
        <?php endwhile; ?>
        </tbody>
		</table>
        
		<?php if ( $wp_query->max_num_pages > 1 ) : ?>
        <nav class="page-navigation">
			<div class="alignleft"><?php next_posts_link( '<span class="meta-nav">Äldre rapporter</span>' ); ?></div>
			<div class="alignright"><?php previous_posts_link( '<span class="meta-nav">Nyare rapporter</span>' ); ?></div>
		</nav>
		
        <?php endif; ?>
        
		<?php else: ?>
		<tr><td></td>
        	<td></td>
        	<td></td>
        	<td></td>
        	<td></td>
        	<td></td>
        	<td></td></tr>
		</tbody>
		</table>

            <div class="tickets-404">Inga rapporter funna</div>

		<?php endif; ?>
        
        <div id="rss-tickets"><a href="<?php bloginfo('rss2_url'); ?>">Prenumeration för nya rapporter</a></div>

<?php get_footer(); ?>